<?php
	class Login extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			if (!isset($_SESSION)) {
			    session_start();
			    session_regenerate_id();
			}
			$this->load->helper("url");
			
		}
		public function index()
		{
			$data=array();
			$this->load->view("login_template", $data);
		}
		public function login_ok()
		{
			if(isset($_REQUEST['aid'])){
				$id=$_REQUEST['aid'];
				$pw=md5($_REQUEST['apw']);
				$result=0;
				$this->load->model("mlogin_ok");
				$data=$this->mlogin_ok->login_ok($id,$pw);
				if(count($data)>0){
					
					$mang=array($data[0]['id'],$data[0]['username'],$data[0]['role']);
					$_SESSION['admindeal']=$mang;
					$_SESSION['lang']=$data[0]['area'];
					
					if(isset($_SESSION['backlink'])){
						$link1=$_SESSION['backlink'];
						unset($_SESSION['backlink']);
						echo '<script>
						window.location.assign("'.$link1.'");
						</script>';
					}else{
					
						echo '<script>
						window.location.assign("'.base_url('listdeal?cid=0').'");
						</script>';
					}
					
				}else{
					echo '<script>
						alert("Dang nhap khong thanh cong !!! Ban vui long kiem tra lai tai khoan hay mat khau !!!");
						window.location.assign("'.base_url('login').'");
					</script>';
				}
		
			}
		}
	}
?>